package com.gainsoft.grevocabuilder;

import android.database.Cursor;
import android.util.Log;

public class Word
{
    private String word_;
    private String meaning_;
    private int learningIndex_ = 0;
    private int id_;
    private Cursor currentCursor;

    public int getLearningIndex_()
    {
	return learningIndex_;
    }

    public void setId_(int id_)
    {
	this.id_ = id_;
    }

    public void setWord_(String word_)
    {
	this.word_ = word_;
    }

    public void setMeaning_(String meaning_)
    {
	this.meaning_ = meaning_;
    }

    public void setLearningIndex_(int learningIndex_)
    {
	this.learningIndex_ = learningIndex_;
    }

    public int getId()
    {
	return id_;
    }

    public String getWord()
    {
	return word_;
    }

    public String getMeaning()
    {
	return meaning_;
    }

    public int getLearningIndex()
    {
	return learningIndex_;
    }

    public void setLearningIndex(int learningIndex)
    {
	this.learningIndex_ = learningIndex;
    }

    public Word()
    {

    }

    public Word(Cursor c)
    {
	this.currentCursor = c;
	this.currentCursor.moveToFirst();
	fillCurrentWord();
    }

    private void fillCurrentWord()
    {
	this.setId_(currentCursor.getInt(currentCursor
		.getColumnIndex(WordList.ID_COL)));
	this.setWord_(currentCursor.getString(currentCursor
		.getColumnIndex(WordList.WORD_COL)));
	this.setMeaning_(currentCursor.getString(currentCursor
		.getColumnIndex(WordList.MEANING_COl)));
	this.setLearningIndex_(currentCursor.getInt(currentCursor
		.getColumnIndex(WordList.LERANINGINDEX_COL)));
    }

    public boolean previousWord()
    {
	boolean isVald = false;
	try
	{
	    if (!currentCursor.isFirst() || !currentCursor.isLast())
	    {
		isVald = currentCursor.moveToPrevious();
		fillCurrentWord();
	    }
	}

	catch (Exception e)
	{
	    Log.e("previousWord", e.toString());
	}
	return isVald;
    }

    public boolean nextWord()
    {
	boolean isVald = false;
	try
	{
	    if (!currentCursor.isFirst() || !currentCursor.isLast())
	    {
		isVald = currentCursor.moveToNext();
		fillCurrentWord();
	    }

	} catch (Exception e)
	{
	    Log.e("nextWord", e.toString());
	}

	return isVald;
    }

}
